package com.arpa.wms.controller.wms;



import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.wms.domain.vo.PrepackagedItemVO;
import com.arpa.wms.service.IPrepackagedDistributionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 预打包分配单 前端控制器
 * </p>
 *
 * @author rfwang
 * @since 2021年7月5日
 */
@Api(tags = "预打包分配单")
@RestController
@NeedLogin
@RequestMapping("/prepackagedDistribution")
@Log4j2
public class PrepackagedDistributionController {

    @Autowired
    private IPrepackagedDistributionService prepackagedDistributionService;
    /**
     * 添加 预打包分配
     *
     * @param prepackagedItemVO
     * @param request
     * @return
     */
    @ApiOperation(value = "添加 预打包分配 ", notes = "添加 预打包分配 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer 123456"),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @NeedLogin
    @PostMapping("/save")
    public Result create(@RequestBody PrepackagedItemVO prepackagedItemVO, HttpServletRequest request) {
        try {
            Result result = prepackagedDistributionService.batchSave(prepackagedItemVO);
            if(!result.isOk()){
                return result;
            }
            return Result.ok("分配成功");
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }
}
